from keras.models import Sequential
from keras.layers import Dense,Activation
from keras.optimizer_v2.gradient_descent import SGD
from sklearn.datasets import load_iris
from sklearn.preprocessing import LabelBinarizer
from sklearn.model_selection._split import train_test_split
import numpy as np

iris=load_iris()
LabelBinarizer().fit_transform(iris['target'])
train_data,test_data,train_target,test_target=train_test_split(iris.data,iris.target,test_size=0.2,random_state=1)
labels_train=LabelBinarizer().fit_transform(train_target)
labels_test=LabelBinarizer().fit_transform(test_target)
model=Sequential(
    [
        Dense(5,input_dim=4),
        Activation('relu'),
        Dense(3),
        Activation('sigmoid'),
    ]
)
# model=Sequential()
# model.add(Dense(5,input=4))
sgd=SGD(lr=0.01,decay=1e-6,momentum=0.9)
model.compile(optimizer=sgd,loss='categorical_crossentropy')
model.fit(train_data,labels_train,epochs=200,batch_size=40)
result=model.predict(test_data)
classes=np.argmax(result,axis=1)
print(classes)
model.save_weights('w')
model.load_weights('w')
